<?php
/**
 * Klass för registrering av användare
 */
class RegView {
	private $getUsernameKey = 'RegUsername';
	private $getPasswordKey = 'RegPassword';
	private $getControllPasswordKey = 'RegControllPassword';
	private $getSubmitKey = 'RegSubmit';
	
	/**
	 * Returnerar värden för registreringsfälten
	 */
	public function GetUsername(){
		if(!empty($_POST[$this->getUsernameKey])){
			return $_POST[$this->getUsernameKey];
		}
		return NULL;		
	} 
	public function GetPassword(){
		if(!empty($_POST[$this->getPasswordKey])){
			return $_POST[$this->getPasswordKey];
		}
		return NULL;		
	}
	public function GetControllPassword(){
		if(!empty($_POST[$this->getControllPasswordKey])){
			return $_POST[$this->getControllPasswordKey];
		}
		return NULL;		
	}
	
	//Kontrollerar om formuläret är submittat
	public function TriedToRegister(){
		if(isset($_POST[$this->getSubmitKey])){
			return true;
		}
		return false;
	}
	/**
	 * Skapar flash meddelande
	 * 
	 * @return string HTML
	 */
	public function DoRegisterBoxFlash($message, $isError){
		return (!empty($message)) ? ($isError) ? "<div id='error'>$message</div>" : "<div id='success'>$message</div>" : "";
	}
	/**
	 * Skapar registreringsormulär
	 * 
	 * @return string HTML
	 */
	public function DoRegisterBox($message = '', $isError = false){
		return "<div class='wrapper'>
					<form method='POST' action=''>
						<div>
							<h1>Registration</h1>
							".$this->DoRegisterBoxFlash($message, $isError)."
							<div>
								<div class='text'> 
								Username:
								</div> 
								<div class='userinfo'> 
									<input type='text' name='$this->getUsernameKey' size='50' value=''> 
								</div>
								<div class='clear'></div> 
							</div>
							<div>
								<div class='text'> 
								Password:
								</div> 
								<div class='userinfo'> 
									<input type='password' name='$this->getPasswordKey' size='50' value=''> 
								</div> 
								<div class='clear'></div> 
							</div> 
							<div>
								<div class='text'> 
								Retype Password:
								</div> 
								<div class='userinfo'> 
									<input type='password' name='$this->getControllPasswordKey' size='50' value=''> 
								</div> 
								<div class='clear'></div> 
							</div> 
							<div>
								<input type='submit' name='".$this->getSubmitKey."' value='Register' />
							</div>
						</div>
					</form>
				</div>";
	}
}
